﻿using System;
using System.IO;
using System.Windows.Forms;

namespace LightLibrary {
	public partial class FormLibraryNew : Form {
		// === Public =================================================================================================
		public LibraryBase NewLibrary { get; private set; }

		public FormLibraryNew() {
			InitializeComponent();
			comboBoxType.Items.AddRange(EnumTools.GetNames<ExtensionTypeGroup>());
			comboBoxType.SelectedIndex = 0;
		}

		// === Private ================================================================================================
		private void BtnCreateClick(object sender, EventArgs e) {
			if(string.IsNullOrEmpty(textBoxName.Text)) {
				MessageBox.Show(@"Name is not specified");
				return;
			}
			if(Directory.Exists(textBoxName.Text)) {
				MessageBox.Show(@"Such a name exists");
				return;
			}
			var type = EnumTools.Parse<ExtensionTypeGroup>(comboBoxType.SelectedItem.ToString());
			NewLibrary = Factory.CreateLibrary(type, textBoxName.Text);
			if(NewLibrary != null) {
				Close();
			}
		}
	}
}